﻿@{
    ViewBag.Title = "GoodClassList";
}

@section scripts
{  
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>    
}

<body>
   <form id="form1" runat="server" method="post" style="height: 100%"> 
    <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" id="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                        <span class="separator"></span>
                    <a class="mini-button" id="new" name="new" iconCls="icon-new" onclick="newBill" plain="true" visible="@ViewBag.cadd">新增</a>
                    <a class="mini-button" id="edit" name="edit" iconCls="icon-edit" onclick="modify" plain="true" visible="@ViewBag.cedit">修改</a>
                    <a class="mini-button" id="delrow" name="delrow" iconCls="icon-remove" onclick="removeInfo" plain="true" visible="@ViewBag.cremove">删除</a>
                    <a class="mini-menubutton" plain="true" iconCls="icon-expand" menu="#popupMenu">查看</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>       
    </div>
       
    <table>
        <tr>
            <td width ="80px" align="right">商户名称: </td>
            <td width ="150px" >
                <input id="Corp" name="Corp" class="mini-combobox" style="width:150px;" showNullItem="false" nullItemText="选择商户"
                            allowInput="false" align="left"  onvaluechanged="CorpSelect"/>
            </td>
            <td width ="80px" align="right">分类名称: </td>
            <td width ="150px" ><input class="mini-textbox" id ="TreeKey" width ="150px" name = "TreeKey" onkeypress="setkeyPressCls()"/></td>
            <td width ="100px" align="center">
                <a class="mini-button" iconCls="icon-search" onclick="findtree" plain="true">查询</a>
            </td>
        </tr>
    </table>
    <div class="mini-fit" >
        <div id="treegrid1" class="mini-treegrid" style="width:100%;height:100%;" 
            url="GetGoodClassList" showTreeIcon="false" fitColumns="false"   pageSize="20"
            treeColumn="FName" idField="FItemID" parentField="FParentID" resultAsTree="false"  
            allowResize="true" expandOnLoad="true" onrowdblclick="modify" >
            <div property="columns">
                <div type="indexcolumn" width="40" headerAlign="center">序号</div>
                <div field="FNumber" width="120px" headerAlign="center">编码</div>    
                <div name="FName" field="FName" width="280px"  headerAlign="center">分类名称</div>       
                <div name="FFreshName" field="FFreshName" width="100px"  headerAlign="center">生鲜设置</div>
                <div name="FRemark" field="FRemark" width="150px"  headerAlign="center">备注</div>         
                <div name="FCorpName" field="FCorpName" width="150px"  headerAlign="center">所属商户</div>
            </div>
        </div>
    </div>     

    <!--menu-->
    <ul id="popupMenu" class="mini-menu" style="display:none;">
        <li id ="getLocaData11"iconCls="icon-redo" onclick="collapseAll">收缩所有</li>
	    <li id="getLocaData1" iconCls="icon-undo" onclick="expandAll">展开所有</li>
        <li class="separator"></li>
        <li id ="getLocaData5"iconCls="icon-reload" onclick="expandLevel(0)">展开二级分类</li>
        <li id ="getLocaData6"iconCls="icon-tip" onclick="expandLevel(1)">展开三级分类</li>
    </ul>

    <script type="text/javascript">
        mini.parse();

        var tree = mini.get("treegrid1");
        function FormShown() {
            //tree.load();
            mini.get("Corp").setUrl('../Corp/ComboBoxList?mjson=' + parent.window.getSystemAppID());
            if (mini.get("Corp").data.length > 0)
                mini.get("Corp").setValue(mini.get("Corp").data[0].id);
            search();
        }
        function CorpSelect() {
            search();
        }

        function collapseAll() {
            tree.collapseAll();
        }

        function expandAll() {
            tree.expandAll();
        }

        function expandLevel(level) {
            tree.expandLevel(level);
            tree.collapseLevel(level+1);
        }

        //搜索资料列表
        function search() {
            var FSystemAppID = parent.window.getSystemAppID();
            var json = '[{"mSystemAppID":"' + FSystemAppID + '","CorpID":' + mini.get("Corp").getValue() + '}]';
            tree.load("GetGoodClassList?mjson=" + json);
            tree.deselectAll();
            mini.getbyName("TreeKey").setValue('');
        }

        ///增加分类
        function newBill() {
            var node = tree.getSelectedNode();
            var data = { action: "new", FClassID: 0, FClassNumber: "00", FClassName: "所有分类" };
            if (node != undefined) {
                data = { action: "new", FClassID: node.FItemID, FClassNumber: node.FNumber, FClassName: node.FName, 
                    FIcon: node.FIcon,FCorpID: mini.getbyName("Corp").getValue()};
            }
            mini.open({
                url: "../GoodClass/GoodClassInfo",
                title: "商品分类", width: 670, height: 400,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    iframe.contentWindow.SetClassData(data);
                },
                ondestroy: function (action) {
                    search();
                }
            });
        }

        //修改分类
        function modify() {
            if (!mini.get("edit").getVisible()) return;
            var node = tree.getSelectedNode();
            if (node) {
                mini.open({
                    url: "../GoodClass/GoodClassInfo",
                    title: "修改分类", width: 670, height: 400,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = {
                            action: "edit", FItemID: node.FItemID, FClassID: node.FItemID, FClassNumber: node.FNumber,
                            FClassName: node.FName, FRemark: node.FRemark, FCorpID: mini.getbyName("Corp").getValue()
                        };
                        iframe.contentWindow.SetClassData(data);
                    },
                    ondestroy: function (action) {
                        search();
                    }
                });
            }
            else {
                mini.showTips({ content: '请选择一行再修改', state: "danger", x: "center", y: "top", timeout: 3000 });
            }
        }

        //删除分类
        function removeInfo() {
            var row = tree.getSelectedNode();
            var FSystemAppID = parent.window.getSystemAppID();
            if (row) {
                mini.confirm("确定要删除选中的记录吗？", "提示",
                    function (action) {
                        if (action == "ok") {
                            var json = "{'FItemID':'" + row.FItemID + "'}";
                            $.post("../GoodClass/delGoodClass", { json: json, mSystemAppID: FSystemAppID }, function (data) {
                                var ret = mini.decode(data);
                                if (ret.status == 1) {
                                    mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                                    tree.removeNode(row);
                                }
                                else {
                                    mini.alert("异常:" + ret.error);
                                }
                            });
                        }
                    });
            } else {
                mini.alert("请选中一条记录");
            }
        }

        function setkeyPressCls() {
            if (event.keyCode == 13) {
                findtree();
            }
        }

        function findtree() {
            var key = mini.get("TreeKey").getValue();
            if (key == "") {
                tree.clearFilter();
            } else {
                key = key.toLowerCase();
                tree.filter(function (node) {
                    var text = node.FName ? node.FName.toLowerCase() : "";
                    if (text.indexOf(key) != -1) {
                        return true;
                    }
                });
            }
        }

    </script>

</form>
</body>